package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.*;

import com.ruoyi.system.domain.Comment_que;
import com.ruoyi.system.domain.dto.CommentDTO;
import com.ruoyi.system.mapper.Comment_queMapper;
import com.ruoyi.system.service.comment_que_Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CommentQueServiceImpl extends ServiceImpl<Comment_queMapper, Comment_que> implements comment_que_Service {

    @Autowired
    private Comment_queMapper commentMapper;
    @Autowired
    private comment_que_Service commentService;


    @Override
    public List<CommentDTO> findFather(List<CommentDTO> comments) {

        for (CommentDTO comment:comments){
            List<CommentDTO> dtoList =commentMapper.selectchildren(comment.getCommentId());

            List<CommentDTO> fatherChildren = new ArrayList<>();

            findChildren(comment,fatherChildren);

            comment.setChildren(fatherChildren);
        }
        return comments;
    }
    public void findChildren(CommentDTO parent,List<CommentDTO> fatherChildren){

        List<CommentDTO> comments = parent.getChildren();

        for (CommentDTO comment: comments){

            if (!comment.getChildren().isEmpty())
            {
                findChildren(comment,fatherChildren);
            }
            fatherChildren.add(comment);


            comment.setChildren(new ArrayList<>());

    }

}
}


